import node as DynamicStructure

class DynamicStack:
    """
    Represents a variable size last-in-first-out collection.
    """
    def __init__(self):
        """
        Initializes a new instance of the DynamicStack class that is empty.
        """
        self.__head  = None
        self.__count = 0
    
    @property
    def count(self):
        """
        Gets the number of elements contained in the DynamicStack.
        """
        return self.__count
    
    def push(self, item):
        """
        Inserts an object at the top of the Stack.
        
        item
            The object to push onto the Stack.
        """
        # Creates a new instance of the class Node.        
        node             = DynamicStructure.Node()
        
        # Assign the item's content into node.information
        node.information = item
        
        # The instance of node through its property next points out to the head
        # of the DynamicStack.
        node.next        = self.__head
        
        # The Dynamic' Stack head points out to node.
        self.__head      = node
        
        # The counter is incremented by 1.
        self.__count    += 1
        
    def pop(self):
        """
        Removes and return the object at the top of the Stack.
        
        returns 
            the first element of the Stack, if the Stack is empty this method
            will return None.
        """
        
        # Checked it out if the Head is pointing out to None, if the result of
        # this evaluation is True, then the stack is empty.
        if self.__head == None:
            print ("The stack is empty.")
            return None
        else:
            # Gets the information value from head.
            information   = self.__head.information
            
            # The head of the DynamicStack will point to the next element of 
            # DynamicStack's head.
            self.__head   = self.__head.next
            
            # The counter is decremented by 1.
            self.__count -= 1
            
            # return Information.
            return information
    
    def peek(self):
        """
        Returns the object at the top of the Stack without removing it.
        
        returns 
            the first element of the Stack, if the Stack is empty this method
            will return None.
        """        
        # Checked it out if the Head is pointing out to None, if the result of
        # this evaluation is True, then the stack is empty.        
        if self.__head == None:
            print ("The stack is empty.")
            return None
        else:
            # Gets the information value from head.
            return self.__head.information
        
    def show(self):
        # This is a method implemented to shows the information contained on 
        # DynamicStack.
        elements = []
        if self.__head != None:
            condition = True
            reference = self.__head
            while condition:
                elements.append(reference.information)
                reference = reference.next
                if reference.next == None:
                    elements.append(reference.information)
                    condition = False
        print (elements)